package com.neutech.solar.util;


import com.neutech.solar.contant.Constant;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

/*
* 图片工具类
* 使用I/O流加载图片
*I:InputStream
*O: OutputStream
*/
public class ImageUtil {

    public static Map<String,Image> maps = new HashMap<>();
    static {
        maps.put("bg",ImageUtil.getImage("bg.png"));
        maps.put("sun",ImageUtil.getImage("sun.png"));
        maps.put("Huo",ImageUtil.getImage("huoxing.png"));
        maps.put("Earth",ImageUtil.getImage("Earth.png"));
        maps.put("Shui",ImageUtil.getImage("shuixing.png"));
        maps.put("Venus",ImageUtil.getImage("jinxing.png"));
        maps.put("Mu",ImageUtil.getImage("muxing.png"));
        maps.put("Tu",ImageUtil.getImage("tuxing.png"));
        maps.put("Hai",ImageUtil.getImage("haiwangxing.png"));
        maps.put("Tian",ImageUtil.getImage("tianwangxing.png"));
        maps.put("Venus",ImageUtil.getImage("jinxing.png"));
        maps.put("smallPlanet",ImageUtil.getImage("xiaoxingxing.png"));

    }


    private ImageUtil(){}
    public static Image getImage(String imageName){
        //加载资源路径
        URL u = ImageUtil.class.getClassLoader().getResource(Constant.IMAGE_PATH_PRE + imageName);
        //提高文件读取效率
        BufferedImage img = null;
        //异常处理
        try{
         img = ImageIO.read(u);
        }catch (Exception e){
            e.printStackTrace();
        }
        return img;
    }
}
